package com.web.transaction;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.domain.Employees;
import com.domain.Treatments;
import com.service.EmployeesService;
import com.service.TreatmentsService;
import com.service.TransactionService;
import com.util.AuthenticateHttpServlet;
import com.util.AuthenticateSession;
@WebServlet("/Transaction/Treatment")
public class TreatmentSalesTransaction extends AuthenticateHttpServlet {

	@Override
	protected void post(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		AuthenticateSession session = (AuthenticateSession)request.getSession().getAttribute("authenticateSession");
		String userId = session.getUserId();
		String treatmentCode = request.getParameter("treatmentCode");
		EmployeesService eService = new EmployeesService();
		Employees e = eService.getEmployeeById(userId);
		TreatmentsService tService = new TreatmentsService();
		Treatments t = tService.getTreatmentByCode(treatmentCode);
		TransactionService service = new TransactionService();
		service.addSales(e.getEmployeeId(), t.getTreatmentCode(), t.getVersion());
		request.getRequestDispatcher("/index").forward(request, response);
	}

}
